Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save only the relative path of the filename for StaticDirStorage #1990

Merged
merged 23 commits into from
Oct 7, 2024

Conversation

amitaibu
Copy link
Collaborator

fixes #1989

@amitaibu
Copy link
Collaborator Author

I still need to verify it locally, but looking here:

createTemporaryDownloadUrlFromPathWithExpiredAt :: (?context :: context, ConfigProvider context) => Int -> Text -> IO TemporaryDownloadUrl
createTemporaryDownloadUrlFromPathWithExpiredAt validInSeconds objectPath = do
publicUrlExpiredAt <- addUTCTime (fromIntegral validInSeconds) <$> getCurrentTime
case storage of
StaticDirStorage -> do
let frameworkConfig = ?context.frameworkConfig
let url = frameworkConfig.baseUrl <> "/" <> objectPath

It looks like it's expecting objectPath to be relative. So Likely this is also a bug fix.

let
requestBody = FormBody { params = [], files = [] }
request = Wai.defaultRequest
requestContext = RequestContext { request, respond = error "respond", requestBody, frameworkConfig = error "frameworkConfig" }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpscholten 👋 I suspect this line, with the error, causes the error I get when running the test

image

How can I make it work? (Copied from here)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That GHC error is unrelated to the error call. I just pushed a workaround via 66518de to master (appartently the INLINE triggers the bug in GHC, but chaging that to an optional inline via INLINABLE not triggers the bug). Can you sync with master and then check again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think now it hits that error

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use IHP.FrameworkConfig.withFrameworkConfig to get a framework config object, like this:

    let withFrameworkConfig = IHP.FrameworkConfig.withFrameworkConfig (pure ())
    describe "createTemporaryDownloadUrlFromPathWithExpiredAt" $ do
        it "returns baseUrl concatenated with objectPath when objectPath does not start with http:// or https://" $ do
            withFrameworkConfig \frameworkConfig -> do
                context <- createControllerContext frameworkConfig
                let ?context = context
                let objectPath = "static/test.txt"
                temporaryDownloadUrl <- createTemporaryDownloadUrlFromPath objectPath

                temporaryDownloadUrl.url `shouldBe` "http://localhost:8000/static/test.txt"

And then use the frameworkConfig passed to createControllerContext instead of the error call

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this I get

  ./IHP/Prelude.hs:92:17: 
  1) IHP.FileStorage.ControllerFunctions.storeFileWithOptions returns the objectPath without the baseUrl
       uncaught exception: ErrorCall
       Could not find FileStorage in config. Did you call initS3Storage from your Config.hs?
       CallStack (from HasCallStack):
         error, called at ./IHP/Prelude.hs:92:17 in main:IHP.Prelude

While trying to figure how to pass a config with the initStaticDirStorage (didn't figure yet), I found aroundAll (withIHPApp WebApplication config) do

Maybe we should use that? (If so, not sure how 😅 )

Copy link
Collaborator Author

@amitaibu amitaibu Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to init the storage here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests passing locally ✌️

@amitaibu amitaibu marked this pull request as ready for review October 6, 2024 18:16
Copy link
Member

@mpscholten mpscholten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks 👍

@mpscholten mpscholten merged commit ff45e48 into master Oct 7, 2024
2 checks passed
@mpscholten mpscholten deleted the amitaibu-patch-5 branch October 7, 2024 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Save only the relative path of the filename in storeFileWithOptions
2 participants